<template>
	<scroll-view class="record_container" scroll-y="true" :enhanced="true" :show-scrollbar="true"
		@scrolltolower="loadMore()">
		<view class="record_item" v-for="(item,index) in recordList" :key="index">
			<view class="item_content">
				<view class="item_info">
					<view class="info_title">
						<view>
							{{item.roomName}}
						</view>
						<view class="info_state" v-if="item.state == '待进行'">
							{{item.state}}
						</view>
						<view class="info_state" v-else :style="{color: item.state == '进行中' ? '#f9c01c' : '#29db6f' }">
							{{item.state}}
						</view>
					</view>
					<view class="info_time">时间：{{item.schedule.split(" ")[0]}} {{item.scheduleRange}}</view>
					<view class="info_address">地址：{{item.address}}</view>
				</view>
			</view>
		</view>
	</scroll-view>
</template>

<script>
	import {
		getUserMeetingRecord
	} from "../../../api/meeting.js"
	export default {
		data() {
			return {
				currentTime: "",
				pageParam: {
					pageIndex: 1,
					pageSize: 10
				},
				recordList: []
			}
		},
		onShow() {
			this.currentTime = new Date().getTime()
			this.pageParam.pageIndex = 1
			this.recordList = []
			this.getList()
		},
		// 下拉刷新
		onPullDownRefresh() {
			setTimeout(() => {
				this.pageParam.pageIndex = 1
				this.recordList = []
				this.getList()
				uni.stopPullDownRefresh();
			}, 1000)
		},
		methods: {
			async getList() {
				const res = await getUserMeetingRecord(this.pageParam)
				if (res) {
					res.items.forEach(item => {
						item.startTime = new Date(item.schedule.split(" ")[0].replaceAll("-", "/") + " " + item
							.scheduleRange.split("-")[0] + ":00").getTime()
						item.endTime = new Date(item.schedule.split(" ")[0].replaceAll("-", "/") + " " + item
							.scheduleRange.split("-")[1] + ":00").getTime()
						if (this.currentTime >= item.startTime && this.currentTime <= item.endTime) {
							item.state = "进行中"
							item.sort = 2
						} else if (this.currentTime < item.startTime) {
							item.state = "待进行"
							item.sort = 1
						} else {
							item.state = "已结束"
							item.sort = 0
						}
					})
					this.recordList = this.recordList.concat(res.items.sort(this.sortHandle))
				}
			},

			// 按sort数值降序排序
			sortHandle(a, b) {
				return b.sort - a.sort
			},

			//加载更多
			loadMore() {
				this.pageParam.pageIndex++;
				this.getList()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.record_container {
		width: 100%;
		min-height: 100vh;
		background: rgb(242, 241, 246);
		padding-top: 10rpx;
		box-sizing: border-box;

		.record_item {
			margin-top: 20rpx;

			.item_content {
				width: 100%;
				height: 226rpx;
				padding-bottom: 32rpx;
				box-sizing: border-box;
				background-color: #fff;

				.item_info {
					padding: 20rpx 34rpx 28rpx 34rpx;
					box-sizing: border-box;
					border-bottom: 1px solid rgb(235, 237, 236);

					.info_title {
						color: rgb(30, 30, 30);
						font-family: 思源黑体;
						font-size: 36rpx;
						font-weight: 500;
						display: flex;
						align-items: center;

						.info_state {
							width: 88rpx;
							height: 36rpx;
							line-height: 36rpx;
							text-align: center;
							background: rgb(223, 239, 255);
							border-radius: 6rpx;
							color: rgb(33, 130, 227);
							font-family: 思源黑体;
							font-size: 24rpx;
							font-weight: 400;
							margin-left: 20rpx;
						}
					}

					.info_time {
						color: rgb(117, 118, 120);
						font-family: 思源黑体;
						font-size: 26rpx;
						font-weight: 400;
						margin: 15rpx 0;
					}

					.info_address {
						width: 100%;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
						color: rgb(117, 118, 120);
						font-family: 思源黑体;
						font-size: 26rpx;
						font-weight: 400;
					}
				}
			}
		}
	}
</style>